<!-- 以下代码为代码生成器生成，生成时间: ${curTime?string("yyyy-MM-dd HH:mm:ss")}，作者：billjiang/475572229@qq.com-->
<section class="content-header">
    <h1>
        ${modelName}管理
        <small>列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="${r'${basePath}'}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">${parFuncName?default('菜单目录')}</a></li>
        <li class="active">${modelName}管理</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="dataTables_filter" id="searchDiv" style="display: none">
                    <!--查询条件-->
                    <#list fields as field>
                        <#if field.isCondition="1">
                            <#if field.tagType="hidden">
                    <input type="${field.tagType}" name="${field.columnName}" id="${field.columnName}">
                            <#elseif field.tagType="text">
                    <input type="search" placeholder="请输入${field.labelName}" title="${field.labelName}" name="${field.columnName}"
                                           class="form-control" id="${field.columnName}" operator="like" likeOption="true">
                            <#elseif field.tagType="datepicker">
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="search" placeholder="开始${field.labelName}" title="${field.labelName}" name="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                    </div>
                    ~
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="search" placeholder="结束${field.labelName}" title="${field.labelName}" name="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                    </div>
                             <#elseif field.tagType="dictSelector">
                    <select name="${field.columnName}" id="${field.columnName}" title="${field.labelName}" data-flag="dictSelector" data-code="${field.dictCode}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width: 120px;" data-blank="true"></select>
                             <#elseif field.tagType="urlSelector">
                    <select name="${field.columnName}" id="${field.columnName}"  title="${field.labelName}"data-flag="urlSelector" data-src="${field.dictCode}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:120px;" data-blank="true"></select>
                             <#elseif field.tagType="normalSelector">
                    <select name="${field.columnName}" id="${field.columnName}"  title="${field.labelName}" class="form-control">
                        <option></option>
                        <option value="0">启用</option>
                        <option value="1">禁用</option>
                    </select>
                     <!--TODO更多类型可在此扩展-->
                     <#elseif field.tagType="radio">
                         <#if !field.dictCode??>
                     <label class="control-label"> <input type="radio" name="${field.columnName}"  value="1"> 是</label> &nbsp;
                     <label class="control-label"> <input type="radio" name="${field.columnName}"  value="0"> 否</label>
                         <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                     <input type="radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                         <#else>
                     <input type="radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                         </#if>
                     <#elseif field.tagType="icheck-radio">
                         <#if !field.dictCode??>
                     <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-green" value="1"> 是</label> &nbsp;
                     <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-green" value="0"> 否</label>
                         <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                     <input type="icheck-radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                         <#else>
                     <input type="icheck-radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                         </#if>
                     <#elseif field.tagType="checkbox">
                         <#if !field.dictCode??>
                     <label class="control-label"> <input type="checkbox" name="${field.columnName}"lang=""  value="1"> 是</label> &nbsp;
                     <label class="control-label"> <input type="checkbox" name="${field.columnName}"  value="0"> 否</label>
                         <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                     <input type="checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                         <#else>
                     <input type="checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                         </#if>
                     <#elseif field.tagType="icheck-checkbox">
                         <#if !(field.dictCode)??>
                     <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-green" value="1"> 是</label> &nbsp;
                     <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-green" value="0"> 否</label>
                         <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                     <input type="icheck-checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                         <#else>
                     <input type="icheck-checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                         </#if>
                            </#if>
                        </#if>
                    </#list>
                    <div class="btn-group">
                        <button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset">重置</button>
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" data-btn-type="add">新增</button>
                        <button type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
                        <button type="button" class="btn btn-default" data-btn-type="delete">删除</button>
                    </div>
                </div>
                <div class="box-body">
                    <table id="${htmlPrefix}_table" class="table table-bordered table-striped table-hover">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    <#list fields as field >
    <#if field.isCondition="1">
    <#if field.tagType = "datepicker" || field.tagType = "dictSelector" || field.tagType = "urlSelector"||field.dictCode?? >
    var form = $("#searchDiv").form({baseEntity: false});
    form.initComponent();
    <#break>
    </#if>
    </#if>
    </#list >
    var ${htmlPrefix}Table, winId = "${htmlPrefix}Win";
    $(function (){
        ${htmlPrefix}Table = new CommonTable("${htmlPrefix}_table", "${queryId}", "searchDiv", null);
        //绑定按钮事件
        $("button[data-btn-type]").click(function () {
            var action = $(this).data("btn-type");
            var rowId = ${htmlPrefix}Table.getSelectedRowId();
            switch (action) {
                case "add":
                    modals.openWin({
                        winId: winId,
                        title: '新增${modelName}',
                        width: "900px",
                        url: basePath + "/${htmlPrefix}/edit"
                    })
                    break;
                case "edit":
                    if (!rowId) {
                        modals.info('请选择要编辑的行');
                        return false;
                    }
                    modals.openWin({
                        winId: winId,
                        title: '编辑${modelName}【' + ${htmlPrefix}Table.getSelectedRowData().name + '】',
                        width: '900px',
                        url: basePath + "/${htmlPrefix}/edit?id=" + rowId
                    });
                    break;
                case 'delete':
                    if (!rowId) {
                        modals.info('请选择要删除的行');
                        return false;
                    }
                    modals.confirm("是否要删除该行数据？", function () {
                        ajaxPost(basePath + "/${htmlPrefix}/delete/" + rowId, null, function (data) {
                            if (data.success) {
                                ${htmlPrefix}Table.reloadRowData();
                            } else {
                                modals.info("${modelName}数据被引用，不可删除！");
                            }
                        });
                    })
                    break;
            }
        })
    })
</script>